/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.smarttmt.smartmanager.bean;

import java.util.Date;
import org.smarttmt.smartmanager.behavior.Preloadable;
import org.smarttmt.smartmanager.util.FacesUtils;

/**
 *
 * @author nicolas
 */
@javax.enterprise.context.SessionScoped
@javax.inject.Named(value = "sessionControllerBean")
public class SessionController implements java.io.Serializable{

    private java.util.Date initDate = new java.util.Date();
    
    public SessionController() {
    }
    
    @javax.annotation.PostConstruct
    public void initSessionController(){
        System.out.println(toString());
    }

    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }
    
    public String executeActionNoParameters(String url){
        
        try {
            Preloadable bean = (Preloadable) FacesUtils.getManagedBean(url+"Bean");
            bean.preload(null);
            //return "/faces/site/"+url+".xhtml";
            return "/site/"+url+".xhtml";
        } catch (Exception e) {
            return null;
        }
        
    }
    
    public String executeAction(String url,java.util.Map<String,Object> parameters){
        
        try {
            Preloadable bean = (Preloadable) FacesUtils.getManagedBean(url+"Bean");
            bean.preload(parameters);
            
            return url;
        } catch (Exception e) {
            return null;
        }
        
    }

    @Override
    public String toString() {
        return "SessionController{" + "initDate=" + initDate + '}';
    }

}
